#include <iostream>
#include <chrono>
#include <memory>
#include "Request/Request.h"
#include "Util/common.h"
#include "Request/RequestManager.h"
#include "Util/SingletonTemplate.h"
#include "Task/HeartbeatTask.h"
#include "Session/TcpSession.h"

std::shared_ptr<Request> sp_Request = std::make_shared<Request>([]()->bool{return true;}, 1, 5, 1);
std::shared_ptr<Request> sp_Request2 = std::make_shared<Request>([]()->bool{return true;}, 2, 4, 2);

int main(int argc, char const *argv[])
{
    std::cout << "Start....\n";
    SingletonTemplate<RequestManager>::Instance();
    SingletonTemplate<HeartbeatTask>::Instance();
    SingletonTemplate<TcpSession>::Instance();
    //todo 初始化连接TcpSession对象
    //todo 读取一些配置

    bool bRegistered = false;//是否已经注册
    /*
    todo:
    1.如果鉴权文件为空，则说明没有注册
    */
    if (bRegistered)
    {
        //todo, 发起鉴权
    }
    else
    {
        //todo,注册， 如果注册成功则重新发起鉴权
    }

    //todo
    //开启心跳任务
    SingletonTemplate<HeartbeatTask>::GetInstance()->Start();
    
    SingletonTemplate<RequestManager>::GetInstance()->AddRequest(sp_Request);
    SingletonTemplate<RequestManager>::GetInstance()->AddRequest(sp_Request2);
    //req.DoRequest();
    char ch;
    while(!std::cin.eof())
    {
        std::cin.get(ch);
        if (ch == 'q')
        {
            break;
        }
        else if (ch == 'r')
        {
            //sp_Request->GetResponse();
            SingletonTemplate<RequestManager>::GetInstance()->SetRequest_GetResponse(1);
        }
        
        
        std::this_thread::sleep_for(std::chrono::milliseconds(1));
        
    }
    std::this_thread::sleep_for(std::chrono::seconds(2));
    return 0;
}
